/**   
 * Copyright © 2018 HIT akeil. Tech Ltd. All rights reserved.
 * 
 * 功能描述：
 * @Package: com.akeil.statusline 
 * @author: snow   
 * @date: 2018年7月29日 上午10:38:52 
 */
package com.akeil.flash.statusline;

import java.util.Observable;
import java.util.Observer;

import com.akeil.flash.event.DeviceInfoNotify;
import com.akeil.flash.event.ENotifyType;
import com.akeil.flash.event.StatusBarNotify;

import flash.Application;

public class StatisBarData implements Observer {
	private ContributionPool cpool = ContributionPool.getInstance();
	
	private TextLineContributionItem sampletemperatureInfo = null;
	private TextLineContributionItem desktopInfo = null;
	private ImageStatusLineContributionItem serialInfo = null;
	private GreenTextStatusLineContributionItem deviceInfo = null;
	
	public StatisBarData(){
		sampletemperatureInfo 		= (TextLineContributionItem)cpool.getContrbution("sampletemperatureInfo");
		desktopInfo 				= (TextLineContributionItem)cpool.getContrbution("desktopInfo");
		serialInfo 					= (ImageStatusLineContributionItem)cpool.getContrbution("serialInfo");
		deviceInfo 					= (GreenTextStatusLineContributionItem)cpool.getContrbution("deviceInfo");
		
		Application.flashData.addObserver(this);
		
		sampletemperatureInfo.setStatus(2);
		desktopInfo.setStatus(2);
	}
	
	@Override
	public void update(Observable o, Object notify) {
		// TODO Auto-generated method stub
		//收到仪器的状态信息
		if(notify instanceof DeviceInfoNotify){
			final DeviceInfoNotify din = (DeviceInfoNotify)notify;
			if(din.getNotifyType().equals(ENotifyType.TEMPERATURE_INFO)){
				sampletemperatureInfo.setValue((float)din.getValue());
			}
			
			if(din.getNotifyType().equals(ENotifyType.DESKTOP_INFO)){
				desktopInfo.setValue((float)din.getValue());
			}
			
			if(din.getNotifyType().equals(ENotifyType.SERIAL_INFO)){
				serialInfo.setStatus(din.getValue() > 0 ? 0 : 1);
				serialInfo.setValue(-1);
			}
		}
		
		if(notify instanceof StatusBarNotify){
			final StatusBarNotify sbn = (StatusBarNotify)notify;
			ENotifyType notifyType = sbn.getNotifyType();
			switch(notifyType){
				
			case DEVICE_INFO:
				deviceInfo.setText(sbn.getStatusContent());
				break;	
			}
		}
	}
	
	private void processAlarmInfo(int alarmInfo) {
	}

}
